﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xaml;
using System.CodeDom;

namespace NeuroSpeech.XamlExtensions
{
    public class ClassWriter : XamlDirectiveWriter 
    {

        public ClassWriter():base(XamlLanguage.Class)
        {

        }


        #region public override void  WriteEndMember(XamlCodeContext context)
        public override void EndMember(XamlCodeContext context)
        {
            string className = context.Peek.Value.Value as string;
            CodeTypeDeclaration TypeDeclaration = context.Type;
            TypeDeclaration.IsClass = true;
            TypeDeclaration.IsPartial = true;
            CodeTypeReference baseType = new CodeTypeReference(context.Peek.Type.UnderlyingType);
            TypeDeclaration.BaseTypes.Add(baseType);
            int index = className.LastIndexOf('.');
            if (index == -1)
            {
                TypeDeclaration.Name = className;
            }
            else
            {
                TypeDeclaration.Name = className.Substring(index + 1);
                context.Namespace.Name = className.Substring(0, index);
            }


        }
        #endregion


    }
}
